jQuery(document).ready(function ($) {
    var school_show_num = [];
    draw(school_show_num, "schoolVcodeimage");
    $("#schoolVcodeimage").on('click',function(){
        draw(school_show_num, "schoolVcodeimage");
    })

    var zwmc;
    var xxmc_htmls = '<option value="">请选择</option>';
    $.ajax({
        type: 'GET',
        url: 'school/api/uncheck/xxmc'
    }).done(function (data, textStatus, jqXHR) {
        var xxmc_vals = [];
        data
        .forEach(function(item) {
            if (item.iszw) {
                zwmc = item.xxmc;
            }
            xxmc_htmls += '<option value="'+item.xxmc+'">';
            xxmc_vals.push(item.xxmc);
        })
        $("#schoolNameDatalist").html(xxmc_htmls);
    }).fail(function (jqXHR, textStatus, errorThrown) {
    });

	$('#studentTab').on("click", function(){
	    window.location = "index.html";
	});

	$('#schoolform').submit(function (event) {
        event.preventDefault();
        var vcode = $("#schoolVcode").val().toLowerCase();
        var num = school_show_num.join("");
        if(vcode == num){
            $("#schoolVcode").val('');
            draw(school_show_num, "schoolVcodeimage");

            var iszw = $('#schoolName').val() === zwmc
            var from = 'school'
            if (iszw) {
                from = 'zw'
            }
            var data = 'username=' + $('#schoolID').val() + '&password=' + $('#schoolName').val() + $('#schoolPassword').val() + "&from=" + from;
            $.ajax({
                data: data,
                timeout: 1000,
                type: 'POST',
                url: 'login'

            }).done(function(data, textStatus, jqXHR) {
                var schoolIDVal = $('#schoolID').val()
                if (iszw) {
                    schoolIDVal = null
                }
                var cookie = JSON.stringify({schoolID: schoolIDVal, schoolName: $('#schoolName').val()});
                $.cookie('bjou_school', cookie);
                window.location = "school/index.html";
            }).fail(function(jqXHR, textStatus, errorThrown) {
                layer.open({
                            type: 1
                            ,offset: 'auto'
                            ,content: '<div style="padding: 20px 100px;">您输入的学校代码或名称有误</div>'
                            ,btn: '关闭全部'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                              layer.closeAll();
                            }
                          });
            });
        } else {
            layer.open({
                type: 1
                ,offset: 'auto'
                ,content: '<div style="padding: 20px 100px;">验证码输入错误！</div>'
                ,btn: '关闭全部'
                ,btnAlign: 'c' //按钮居中
                ,shade: 0 //不显示遮罩
                ,yes: function() {
                    layer.closeAll();
                }
            });
            $("#schoolVcode").val('');
            draw(school_show_num);
        }
    });
});


layui.use('layer', function(){ //独立版的layer无需执行这一句
	var layer = layui.layer;
});

